//
//  HRStatusCell.swift
//  microBlog
//
//  Created by HR_W on 16/5/24.
//  Copyright © 2016年 admin. All rights reserved.
//

import UIKit
import SnapKit


class HRStatusCell: UITableViewCell {
    
    
    var toolbarTopCons: Constraint?
    
    var statusViewModel: HRStatusViewModel? {
    
        didSet {
            
            statusToolBar.statusViewModel = statusViewModel
            statusOriginalView.statusViewModel = statusViewModel
            
            toolbarTopCons?.uninstall()
            
            if statusViewModel?.status?.retweeted_status == nil {
                statusRetweetedView.statusViewModel = nil
                
                statusRetweetedView.hidden = true
                
                statusToolBar.snp_updateConstraints(closure: { (make) in
                    
                    self.toolbarTopCons = make.top.equalTo(statusOriginalView.snp_bottom).constraint
                })
            }else{
            
            
            
            statusRetweetedView.statusViewModel = statusViewModel
                
                statusRetweetedView.hidden = false
                
                statusToolBar.snp_updateConstraints(closure: { (make) in
                    self.toolbarTopCons = make.top.equalTo(statusRetweetedView.snp_bottom).constraint
                })
            
            }
                
    
           
        }
    
    
    }
    
    

    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
       
        //self.backgroundColor = randomColor()
        self.selectionStyle = .None
        
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    private func setupUI() {
    
        contentView.addSubview(statusOriginalView)
        contentView.addSubview(statusRetweetedView)
        contentView.addSubview(statusToolBar)
        
        
        
        
        
        statusOriginalView.snp_makeConstraints { (make) in
            
            make.left.right.top.equalTo(self.contentView)
            //make.height.equalTo(150)
        }
        
        statusRetweetedView.snp_makeConstraints { (make) in
            make.top.equalTo(statusOriginalView.snp_bottom)
            make.left.right.equalTo(contentView)
        }
        
        statusToolBar.snp_makeConstraints { (make) in
           self.toolbarTopCons = make.top.equalTo(statusRetweetedView.snp_bottom).constraint
            make.right.left.equalTo(self.contentView)
            make.height.equalTo(36)
        }
        
        contentView.snp_makeConstraints { (make) in
            
            make.top.left.right.equalTo(self)
            make.bottom.equalTo(statusToolBar.snp_bottom)
        }
        
    }
    //原创微博视图
    private lazy var statusOriginalView: HRStatusOriginalView = HRStatusOriginalView()
    //转发微博视图

    
    private lazy var statusRetweetedView: HRStatusRetweetedView = HRStatusRetweetedView()
    
    //底部工具条
    private lazy var statusToolBar: HRStatusToolBar = HRStatusToolBar()
}
